package com.example.shop_2211.adapter

import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.base.entity.CategoryEntity
import com.example.base.entity.Child
import com.example.shop_2211.R
import com.example.shop_2211.utils.GlideUtils

class TwoAdapter:BaseQuickAdapter<CategoryEntity,BaseViewHolder>(R.layout.item_two) {
    override fun convert(holder: BaseViewHolder, item: CategoryEntity) {
        holder.setText(R.id.two_title,item.name)
        //找到rv
        val rv = holder.getView<RecyclerView>(R.id.two_rv)
        val twoChildAdapter = TwoChildAdapter()
        twoChildAdapter.data.clear()
        twoChildAdapter.data.addAll(item.child)
        rv.adapter =twoChildAdapter
        rv.layoutManager = GridLayoutManager(context,3)
    }
}

class TwoChildAdapter:BaseQuickAdapter<Child,BaseViewHolder>(R.layout.item_two_child){
    override fun convert(holder: BaseViewHolder, item: Child) {
        GlideUtils.loadCircleImage(context,item.extra,holder.getView(R.id.child_iv))
        holder.setText(R.id.child_tv,item.name)
       /* holder.itemView.setOnClickListener {
            ARouter.getInstance().build("/app/SearchActivity")
                .withInt("cid",item.id)
                .withString("cname",item.name)
                .navigation()
        }*/
    }

}